<template>
  <!-- 智慧工地平台-安全管理 -->
  <popup :show="safetyShow" title="智慧工地平台-安全管理" @onClone="safetyFun">
    <div class="safetyDialog">
      <section class="buttonBox">
        <ul>
          <li
            v-for="(item, index) in buttonList"
            :key="index"
            :class="buttonIndex == index ? 'active' : ''"
            @click="buttonIndex = index"
          >
            {{ item }}
          </li>
        </ul>
        <ul v-show="buttonIndex == 0">
          <li
            v-for="(item, index) in dateList"
            :key="index"
            :class="dateIndex == index ? 'active' : ''"
            @click="
              dateIndex = index;
              scortData();
            "
          >
            {{ item.examinationTime }}
          </li>
        </ul>
        <ul v-show="buttonIndex == 1">
          <li
            v-for="(item, index) in ThreeMonths"
            :key="index"
            :class="tmIndex == index ? 'active' : ''"
            @click="
              tmIndex = index;
              dangerList();
            "
          >
            {{ item }}
          </li>
        </ul>
      </section>
      <div class="titleBox">
        <div v-if="buttonIndex == 0">
          <el-table
            :data="JCData"
            height="500"
            style="width: 100%; height:50px,margin-top: 20px,border: 1px solid #495A79,background: '#104584'"
            :row-style="{ height: 50 + 'px' }"
            :header-cell-style="{
              background: '#104584',
              color: '#fff',
              borderColor: '#495A79',
              height: 50 + 'px',
              padding: 0 + 'px',
            }"
            :cell-style="{
              background: '#0C2451',
              color: '#fff',
              height: 50 + 'px',
              borderColor: '#495A79',
              padding: 6 + 'px',
            }"
            :span-method="objectSpanMethod"
          >
            <!-- @row-click="rowClick" -->
            <el-table-column prop="dangerItemNumber" label="序号" width="80">
            </el-table-column>
            <el-table-column prop="dangerType" label="项目" width="150">
            </el-table-column>
            <el-table-column prop="" label="标准分" width="80">
              <template slot-scope="scope">
                <span>{{ scope.row.dangerType == "安全管理" ? 1 : 5 }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="dangerItemContent" label="检查内容及要求">
            </el-table-column>
            <el-table-column prop="dangerItemScore" label="实得分" width="100">
            </el-table-column>
          </el-table>
        </div>
        <div v-if="buttonIndex == 1">
          <el-table
            :data="tableData"
            style="width: 100%; height:50px,margin-top: 20px,border: 1px solid #495A79,background: '#104584'"
            :row-style="{ height: 50 + 'px' }"
            :header-cell-style="{
              background: '#104584',
              color: '#fff',
              borderColor: '#495A79',
              height: 50 + 'px',
              padding: 0 + 'px',
            }"
            :cell-style="{
              background: '#0C2451',
              color: '#fff',
              height: 50 + 'px',
              borderColor: '#495A79',
              padding: 6 + 'px',
            }"
            @row-click="rowClick"
          >
            <el-table-column prop="noticeNumber" label="通知单编号">
            </el-table-column>
            <el-table-column
              prop="constructionEnterpriseName"
              label="施工单位名称"
              width="300"
            >
            </el-table-column>
            <el-table-column prop="projectManagerName" label="项目经理名字">
            </el-table-column>
            <el-table-column prop="personResponsibleName" label="责任人名字">
            </el-table-column>
            <el-table-column prop="detectTime" label="隐患发现时间">
            </el-table-column>
            <el-table-column prop="dangerType" label="隐患类别">
            </el-table-column>
            <el-table-column prop="treatmentType" label="处理方式">
            </el-table-column>
            <el-table-column prop="fineAmount" label="处罚金额">
            </el-table-column>
            <el-table-column prop="treatmentDeadline" label="处理期限">
            </el-table-column>
            <el-table-column prop="hasPass" label="是否报验">
              <template slot-scope="scope">
                <span>{{
                  scope.row.hasPass == 1
                    ? "处理中"
                    : scope.row.hasPass == 2
                    ? "已完成"
                    : "未报检"
                }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <section class="pagination" v-show="buttonIndex == 1">
        <select v-model="selected" @change="selectChange">
          <option
            v-for="(option, idx) in options"
            :key="idx"
            :value="option.value"
          >
            {{ option.text }}
          </option>
        </select>
        <MoPaging
          :page-index="currentPage"
          :total="count"
          :page-size="pageSize"
          @pageChange="pageChange"
        >
        </MoPaging>
        <div class="pege">
          跳至
          <input type="tel" v-model="page" @blur="inputBlur" />
          页
        </div>
      </section>
    </div>
  </popup>
</template>

<script>
import popup from "../../popup.vue";
import MoPaging from "../mo-paging.vue";
import api from "@/util/api";
import * as dayjs from "dayjs";
export default {
  components: {
    popup,
    MoPaging,
  },
  name: "safetyDialog",
  data() {
    return {
      safetyDialog: `<div>1111111111</div>`,
      buttonList: ["安全检查", "安全隐患"],
      buttonIndex: 0,
      ThreeMonths: [],
      tmIndex: 0,
      dateList: [],
      dateIndex: 0,
      tableData: [],
      JCData: [],
      page: 1,
      pageSize: 7, //每页显示10条数据
      currentPage: 1, //当前页码
      count: 100, //总记录数,
      selected: 7,
      options: [
        { text: "5条/页", value: 5 },
        { text: "7条/页", value: 7 },
        { text: "9条/页", value: 9 },
      ],
    };
  },
  computed: {
    safetyShow: function () {
      return this.$store.state.safetyShow;
    },
  },
  mounted() {
    this.getThreeMonths();
    this.getSaftyExamination();
  },
  methods: {
    safetyFun(data) {
      let that = this;
      that.$store.dispatch("changeFun", {
        str: "safetyShow",
        cont: data,
      });
    },
    // 该行被点击
    rowClick(row, column, event) {
      console.log("208 row", row);
      this.$store.dispatch("changeFun", {
        str: "threeLevelShow",
        cont: true,
      });
      this.$store.dispatch("changeFun", {
        str: "threeLevel",
        cont: {
          type: "security",
          id: row.id,
        },
      });
    },
    getSpanArr(data) {
      // data就是我们从后台拿到的数据
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1);
          this.pos = 0;
        } else {
          // 判断当前元素与上一个元素是否相同
          if (data[i].id === data[i - 1].id) {
            this.spanArr[this.pos] += 1;
            this.spanArr.push(0);
          } else {
            this.spanArr.push(1);
            this.pos = i;
          }
        }
        console.log(this.spanArr);
      }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // if (columnIndex === 0 || columnIndex === 1) {
      //   const _row = this.spanArr[rowIndex];
      //   const _col = _row > 0 ? 1 : 0;
      //   console.log(`rowspan:${_row} colspan:${_col}`);
      //   return {
      //     // [0,0] 表示这一行不显示， [2,1]表示行的合并数
      //     rowspan: _row,
      //     colspan: _col
      //   };
      // }
    },
    //从page组件传递过来的当前page
    pageChange(page) {
      this.currentPage = page;
      this.page = page;
      this.getFileList();
    },
    // 每页条数改变
    selectChange() {
      this.pageSize = this.selected;
      this.getFileList();
    },
    // 当前页改变
    inputBlur() {
      // this.currentPage = this.page
      this.pageChange(+this.page);
    },
    /** API */
    // 获取近三个月时间
    getThreeMonths() {
      api.getThreeMonths({}, (res) => {
        res.data.data.map((item) => {
          this.ThreeMonths.push(dayjs(item).format("YYYY-MM"));
        });
        this.dangerList();
        // this.getUnQualifiedList();
        // this.getAcceptanceList();
      });
    },
    //
    getSaftyExamination() {
      api.getSaftyExamination({}, (res) => {
        res.data.data.map((item) => {
          item.examinationTime = dayjs(item.examinationTime).format(
            "YYYY-MM-DD"
          );
        });
        this.dateList = res.data.data;
        this.scortData();
      });
    },
    // 大屏二级展示数据:安全评分数据
    scortData() {
      api.scortData(
        {
          saftyExaminationNumber:
            this.dateList[this.dateIndex].saftyExaminationListNumber,
        },
        (res) => {
          this.JCData = res.data.data;
          console.log(res);
          // this.getSpanArr(this.JCData)
        }
      );
    },
    // 大屏二级展示数据:安全隐患列表
    dangerList() {
      api.dangerList(
        {
          month: this.ThreeMonths[this.tmIndex],
          pageNum: this.currentPage,
          pageSize: this.pageSize,
        },
        (res) => {
          this.tableData = res.data.list;
          this.count = res.data.total;
        }
      );
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.safetyDialog {
  width: 1200px;
  height: 700px;
  overflow: auto;
  .buttonBox {
    width: 100%;
    height: auto;
    padding-bottom: 30px;
    display: flex;
    justify-content: space-between;
    ul {
      display: flex;
      justify-content: space-between;
      color: #fff;
      li {
        list-style-type: none;
        width: 100px;
        height: 43px;
        background-color: #135ba7;
        border-radius: 4px;
        text-align: center;
        line-height: 43px;
        margin-left: 12px;
        cursor: pointer;
      }
      li:nth-child(1) {
        margin: 0;
      }
      .active {
        background-color: #ff891d;
      }
    }
  }
  .titleBox {
    width: 1200px;
    height: 520px;
    position: relative;
  }
  .pagination {
    width: fit-content;
    margin: 0 auto;
    padding-top: 10px;
    select {
      width: 95px;
      height: 40px;
      border: 1px solid #e6ecf3;
      border-radius: 2px;
      margin-left: 12px;
      padding-left: 12px;
      line-height: 40px;
      font-size: 15px;
      text-align: center;
      color: #fff;
      overflow: hidden;
      background-color: #00000000;
      option {
        color: #000;
      }
    }
    .pege {
      display: inline-block;
      color: #fff;
      font-size: 15px;
      input {
        width: 63px;
        height: 40px;
        color: #fff;
        border: 1px solid #e6ecf3;
        border-radius: 2px;
        padding-left: 6px;
        background-color: #00000000;
        box-sizing: border-box;
      }
    }
  }
  .el-table--border::after,
  .el-table--group::after,
  .el-table::before {
    background-color: #495a79 !important;
  }

  .el-table__footer-wrapper,
  .el-table__header-wrapper,
  .el-table__header,
  .el-table thead {
    background-color: #0c2451 !important;
  }
  .el-table th,
  .el-table tr {
    background-color: #0c2451 !important;
  }
  .el-table--fit td.gutter,
  .el-table--fit th.gutter {
    background-color: #0c2451 !important;
  }

  .el-table,
  .el-table__expanded-cell {
    background-color: #0c2451 !important;
  }
  ::-webkit-scrollbar {
    width: 7px;
    height: 10px;
    background-color: transparent;
  } /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
  ::-webkit-scrollbar-track {
    background-color: #0c2451;
  } /*定义滚动条轨道 内阴影+圆角*/
  ::-webkit-scrollbar-thumb {
    background-color: #495a79;
    border-radius: 6px;
  } /*定义滑块 内阴影+圆角*/
  .scrollbarHide::-webkit-scrollbar {
    display: none;
  }
  .scrollbarShow::-webkit-scrollbar {
    display: block;
  }
}
</style>

